package com.adingxiong.cft.service.impl;

import com.adingxiong.cft.entity.LoginLog;
import com.adingxiong.cft.mapper.LoginLogMapper;
import com.adingxiong.cft.service.ILoginLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 用户登录日志 服务实现类
 * </p>
 *
 * @author xiongc
 * @since 2020-09-27
 */
@Service
public class LoginLogServiceImpl extends ServiceImpl<LoginLogMapper, LoginLog> implements ILoginLogService {

    @Override
    public LoginLog getByUserId(Integer id) {
        QueryWrapper<LoginLog> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(LoginLog::getUserId ,id);
        return getOne(wrapper);
    }

    @Override
    public boolean update(Integer userId, Date date) {

        QueryWrapper<LoginLog> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(LoginLog::getUserId ,userId);

        LoginLog loginLog = new LoginLog();
        loginLog.setLogoutTime(date);
        return update(loginLog,wrapper);
    }
}
